package com.zhanghu.backendZray;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.util.unit.DataSize;

import javax.servlet.MultipartConfigElement;

@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
@MapperScan({"com.zhanghu.backendZray.mapper"})
@SpringBootApplication
@ConfigurationPropertiesScan
@EnableScheduling
@ServletComponentScan
public class BackendZrayApplication {

    public static void main(String[] args) {
        SpringApplication.run(BackendZrayApplication.class, args);
    }

    /**
     * 解决The field file exceeds its maximum permitted size of 1048576 bytes.报错
     * Spring Boot默认文件上传大小为1M，多文档上传中总是出现文件大小超出限度
     *
     * @return
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        // 单个文件最大 10MB
        // 这是文件级别
        factory.setMaxFileSize(DataSize.ofBytes(10 * 1024 * 1024));
        //factory.setMaxFileSize("10240KB"); //KB,MB
        // 设置总上传数据总大小 20MB
        // 这个是请求级别，body的大小
        factory.setMaxRequestSize(DataSize.ofBytes(20 * 1024 * 1024));
        //factory.setMaxRequestSize("102400KB");
        return factory.createMultipartConfig();
    }

}
